package com.qire.manhua.dal.converter;

import com.google.gson.Gson;
import com.qire.antsbinder.dal.ParamsConverter;
import com.qire.common.collect.ListUtil;

import java.util.List;

/**
 * 批量删除收藏夹接口中转换comicId列表位JSON格式。
 */
public class BatchDelFavoriteConverter implements ParamsConverter<String, List<String>> {

    @Override
    public String change(List<String> comicIdList) {
        if(ListUtil.isEmpty(comicIdList)) {
            return "";
        }

        int size = comicIdList.size();
        ComicWrapper[] comicWrappers = new ComicWrapper[size];
        for(int index = 0; index < size; index++) {
            comicWrappers[index] = new ComicWrapper(comicIdList.get(index), 0);
        }

        return new Gson().toJson(comicWrappers);
    }

    private class ComicWrapper {
        String book_id;
        int btype;//接口遗留问题，由于以前存在漫画和小说，所以需要传递类型，目前小说已被丢弃所以该字段位0
        ComicWrapper(String book_id, int btype) {
            this.book_id = book_id;
            this.btype = btype;
        }
    }

}
